﻿using System;
using System.Collections.Generic;
/// <summary>
/// 卡牌值基类
/// </summary>
/// <typeparam name="ValueType"></typeparam>
[Serializable]
public class PropertyValue<ValueType>
{
    public ValueType val;
    public string discript;
    public GMConfig.PropertyType elemeType;
    
    /// <summary>
    /// 如果实现了其它构造函数，默认的也要实现
    /// 不然再解析json的时候会报错，找不到构造函数
    /// </summary>
    /// <typeparam name="ValueType"></typeparam>
    public PropertyValue(){

    }
    public PropertyValue(ValueType _val,string _dis,GMConfig.PropertyType _elemeType = GMConfig.PropertyType.UnPoint){
        val = _val;
        discript = _dis;
        elemeType = _elemeType;
    }
    public void InitData(PropertyValue<ValueType> item){
        val = item.val;
        discript = item.discript;
        elemeType = item.elemeType;
    }
    /// <summary>
    /// 获去属性描述
    /// </summary>
    /// <returns></returns>
    public string GetDiscript(bool isReplace = true)
    {
        if(isReplace) return LTLocalization.GetText2(discript, val.ToString());
        return LTLocalization.GetText2(discript);
    }
    /// <summary>
    /// 获得属性值
    /// 对多个或含有百分比的进行转换
    /// </summary>
    /// <returns></returns>
    public List<float> GetVal(){
        var tempList = new List<float>();
        var valStr = val.ToString();
        var isPercent = false;
        //判断是不是百分比
        if(valStr.Contains("%")) {
            isPercent = true;
            valStr = valStr.Replace("%","");
        }else if(GetDiscript(false).Contains("%")){
            isPercent = true;
        }
        var tempVal = valStr.Split('-');
        for(int i = 0;i < tempVal.Length;i++){
            float _val = float.Parse(tempVal[i]);
            if(isPercent) _val /= 100;
            tempList.Add(_val);
        }
        return tempList;
    }
}